package com.zyzg.utils;

public class DistanceUtils {

    private static final double EARTH_RADIUS = 6371000; // 地球半径（米）

    public static double calculateDistance(double lng01, double lat01, double lng02, double lat02) {
        double lat1 = Math.toRadians(lat01);
        double lon1 = Math.toRadians(lng01);
        double lat2 = Math.toRadians(lat02);
        double lon2 = Math.toRadians(lng02);

        double dLat = lat2 - lat1;
        double dLon = lon2 - lon1;

        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
                Math.cos(lat1) * Math.cos(lat2) *
                        Math.sin(dLon / 2) * Math.sin(dLon / 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        return EARTH_RADIUS * c;
    }
}
